package com.example.springcloudwinter.service;

import com.example.springcloudwinter.bo.BusinessBo;
import com.example.springcloudwinter.dto.ResultEntity;
import com.example.springcloudwinter.mapper.BusinessMapper;
import com.example.springcloudwinter.po.BusinessPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessService {
    @Autowired
    private BusinessMapper businessMapper;

    public ResultEntity<?> getDetailedInformation(int businessId){
        ResultEntity<BusinessBo> result=new ResultEntity<>();
        BusinessPo business=businessMapper.getByBusinessId(businessId);
        if(business==null){
            result.setCode(701);
        }else{
            BusinessBo businessBo=new BusinessBo(business);
            result.setDetail(businessBo).setCode(200);
        }

        return result;
    }

    public ResultEntity<?> getListByCategory(int category){
        ResultEntity<List<?>> result=new ResultEntity<>();
        List<?> businessList;
        if(category==0){
            businessList=businessMapper.getAllList();
        }else{
            businessList=businessMapper.getListByCategory(category);
        }
        result.setDetail(businessList).setCode(200);
        return result;
    }
}
